$(function(){
	new Vue({
		el:'#addManagerApp',
		data:{
			fullscreenLoading:false,
			uploadUrl:"http://39.100.131.147:8888/goods/address/uploadFile",
			fileList:[],
			form:{
				username:"",
				password:"",
				configPassword:"",
				nickname:"",
				grade:"",
			}
		},
		created:function(){
			parent.vueData.$data.hreHtml = "../addManager/index.html";
			parent.vueData.activeIndex = "4";
			parent.vueData.getLeftNav("4")
			parent.vueData.$data.categoryIndex = 1
		},
		methods:{
			//删除头像
			beforeRemove(file,fileList){
				let index = this.fileList.findIndex( fileItem => {
				       return fileItem.url === file.url
				   })
				  this.fileList.splice(index, 1)
				return true;
			},
			//上传头像
			handleImgSuccess(response,file,fileList){
				if (response.code == 100) {
					this.form.photo= response.result
					this.fileList.push({
						name: "用户头像",
						url: response.result,
					})
				}
			},
			handleImgExceed(files, fileList) {
				this.$message.warning("用户头像只能上传一张图片")
			},
			configManagerSuper(){
                  if(stringEmpty(this.form.username)){
					  this.$message.error("用户名不能为空");
					  return
				  }
				  
				  if (stringEmpty(this.form.password)){
					 this.$message.error("用户密码不能为空");
					 return 
				  }
				  if (stringEmpty(this.form.configPassword)){
				  		this.$message.error("确认密码不能为空");
				  		return 
				  }
				  if (this.form.password != this.form.configPassword){
				  		this.$message.error("两次输入密码不一致");
				  		return 
				  }
				  if (stringEmpty(this.form.nickname)){
				  		this.$message.error("用户昵称不能为空");
				  		return 
				  }
				  if (stringEmpty(this.form.grade)){
				  		this.$message.error("用户级别不能为空");
				  		return 
				  }
				  if(this.fileList.length<=0){
					    this.$message.error("用户头像不能为空");
					    return 
				  }
				  console.log(this.fileList);
				  this.fullscreenLoading = true;
				  axios({
				  	url: POSTURL.createAdminUser,
				  	method: 'post',
				  	data: this.form
				  }).then(response => {
				  	this.fullscreenLoading = false;
				  	if (response.data.code === 100) {
				  		this.$message({
				  			showClose: true,
				  			message: response.data.message,
				  			type: 'success'
				  		});
				  	} else {
				  		this.$message.error(response.data.message);
				  	}
				  }).catch(error => {
				  	this.fullscreenLoading = false;
				  	console.log(error);
				  	this.$message.error('服务器出错!');
				  })
				  
			},
		}
	})
})